#include<stdio.h>
#include<string.h>
int main()
{
    FILE *fp1 = NULL;
    FILE *fp2 = NULL;
    char file1[100];
    char file2[100];
    int line = 0,i;
    char ch;
    fp1 = fopen("D:\\a.txt" , "r");
    fp2 = fopen("D:\\b.txt" , "r");
    if(fp1 == NULL || fp2 == NULL)
    {
        printf("文件打开失败！\n");
        return 0;
    }
    while(fgetc(fp1) && fgetc(fp2))//假设文件每一行结束都有结束标识符
    {
        for(i=0;;i++)
        {
            ch=fgetc(fp1);
            if(feof(fp1))
            {
                break;
            }
            else
            {
                file1[i]=ch;
            }
        }
        for(i=0;;i++)
        {
            ch=fgetc(fp2);
            if(feof(fp2))
            {
                break;
            }
            else
            {
                file2[i]=ch;
            }
        }
        line++;
        if(strcmp(file1,file2) != 0)
        printf("文件%s与文件%s的第%d行不匹配\n",file1,file2,line);
    }
    if(!fgetc(fp1))
    {
        printf("文件%s的行数少于文件%s,在第%d行之后两文件的内容均不匹配",file1,file2,line);
    }
    if(!fgetc(fp2))
    {
        printf("文件%s的行数少于文件%s,在第%d行之后两文件的内容均不匹配",file2,file1,line);
    }
    fclose(fp1);
    fclose(fp2);
    return 0;
}
